using System;
using System.IO;
using THANHTUNGO.Portal.Components.UI;

namespace THANHTUNGO.Portal.Modules.FileExpress
{
    public enum FEPages
    {
        Upload,
        Management
    }

    public partial class Main : PortalModuleControl
    {
        private void loadChildControl()
        {
            FEPages page;
            string m_baseDir = "~/Modules/FileExpress/";
            string pageName;
            pageName = Request.QueryString["Page" + this.ModuleID];
            if (pageName == null)
            {
                page = FEPages.Upload;
            }
            else
            {
                page = (FEPages)Enum.Parse(typeof(FEPages), Request.QueryString["Page" + this.ModuleID], true);
            }

            string src = string.Format("{0}Pages/{1}.ascx", m_baseDir, page);
            if (src.IndexOf("/Mod_") >= 0)
                src = src.Replace("/Mod_", "/Mod/");
            if (src.IndexOf("/Admin_") >= 0)
                src = src.Replace("/Admin_", "/Admin/");
            if (src.IndexOf("/Help_") >= 0)
                src = src.Replace("/Help_", "/Help/");

            YAFPage ctl = (YAFPage) LoadControl(src);
            ctl.ParentControl = this;
            this.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.loadChildControl();
            GridView1.DataSource = Directory.GetFiles(Server.MapPath("~/Uploads/Downloads"));
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            YAFUrlBuilder.Redirect(this.ModuleID, FEPages.Management);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            YAFUrlBuilder.Redirect(this.ModuleID, FEPages.Upload);
        }
    }
}